//
//  YINetWorkingManager.m
//  一点互助
//
//  Created by rimi on 16/8/20.
//  Copyright © 2016年 shen. All rights reserved.
//

#import "YINetWorkingManager.h"

static NSString *url = @"http://www.scxxhs.com/huzhu/index.php?";
@implementation YINetWorkingManager

+ (void)GETWithURL:(NSString *)URLStr parameters:(NSDictionary *)dictionary success:(void(^)(id responseObject))responseObjc filed:(void(^)(NSError *error))err
{
       
       URLStr = [NSString stringWithFormat:@"%@%@",url,URLStr];
       AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
       // 有的返回的数据格式，AFNetWorking不支持解析，所以我们要设置一下让AFNetWorking支持。
       [manager.responseSerializer setAcceptableContentTypes:[NSSet setWithObjects:@"text/html", @"application/json", @"text/json", @"text/javascript",@"text/html",@"text/css", @"text/plain", @"application/x-javascript", @"application/javascript",nil]];
       //拼接网址字符串
       URLStr = [URLStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
       //实现GET网络请求
       [manager GET:URLStr parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
              //数据回调
              responseObjc(responseObject);
       } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
              //数据回调
              err(error);
       }];
}
+ (void)POSTWithURL:(NSString *)URLStr parameters:(NSDictionary *)dictionary success:(void (^)(id))responseObjc filed:(void (^)(NSError *))err
{
       URLStr = [NSString stringWithFormat:@"%@%@",url,URLStr];
       AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
       [manager.responseSerializer setAcceptableContentTypes:[NSSet setWithObjects:@"text/html", @"application/json", @"text/json", @"text/javascript",@"text/html",@"text/css", @"text/plain", @"application/x-javascript", @"application/javascript",nil]];
       URLStr = [URLStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
       [manager POST:URLStr parameters:dictionary progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
              responseObjc(responseObject);
       } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
              err(error);
       }];
}
@end
